﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.OracleClient;

namespace Projekt_GUI.Forms
{
    public partial class KundeNeu : Form
    {
        public KundeNeu()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.Manual;            
            Point openUpHere = new Point(0, 0);
            this.Location = openUpHere;
        }

        private void KundeNeu_Load(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string date;
                date = dateTimePicker1.Value.Date.Day.ToString() + "." + dateTimePicker1.Value.Date.Month.ToString() + "." + dateTimePicker1.Value.Date.Year.ToString();

                using (OracleConnection con = new OracleConnection("Data Source=localhost; User Id=PROJEKT; Password=PROJEKT"))
                {
                    con.Open();
                    OracleCommand com = con.CreateCommand();
                    com.CommandText = "INSERT INTO Kunden VALUES(SQ_KUNDEN.NEXTVAL, '" + textBox1.Text + "', '" + textBox2.Text + "', to_date('" + date + "'), '" + textBox3.Text + "', '" + textBox4.Text + "', '" + textBox5.Text + "', '" + textBox6.Text + "', '" + textBox7.Text + "', " + numericUpDown1.Value.ToString() + ")";

                    com.ExecuteNonQuery();
                }

                foreach (Form f in MdiParent.MdiChildren)
                {
                    if (f.Text == "Kunden")
                    {
                        ((KundeÜbersicht)f).Refresh();
                    }
                }
            }
            catch (OracleException ex)
            {
                MessageBox.Show(ex.Message, "Oracle Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
                Close();
        }
    }
}
